home *** CD-ROM | disk | FTP | other *** search
/ Champak 120 / Vol 120.iso / games / how_t000.swf / scripts / __Packages / mx / transitions / Tween.as < prev   
Encoding:
Text File  |  2010-11-09  |  5.2 KB  |  245 lines

  1. class mx.transitions.Tween
  2. {
  3.    var obj;
  4.    var prop;
  5.    var begin;
  6.    var useSeconds;
  7.    var _listeners;
  8.    var addListener;
  9.    var prevTime;
  10.    var _time;
  11.    var looping;
  12.    var _duration;
  13.    var broadcastMessage;
  14.    var isPlaying;
  15.    var _fps;
  16.    var prevPos;
  17.    var _pos;
  18.    var change;
  19.    var position;
  20.    var _intervalID;
  21.    var _startTime;
  22.    static var version = "1.1.0.52";
  23.    static var __initBeacon = mx.transitions.OnEnterFrameBeacon.init();
  24.    static var __initBroadcaster = mx.transitions.BroadcasterMX.initialize(mx.transitions.Tween.prototype,true);
  25.    function Tween(obj, prop, func, begin, finish, duration, useSeconds)
  26.    {
  27.       mx.transitions.OnEnterFrameBeacon.init();
  28.       if(!arguments.length)
  29.       {
  30.          return undefined;
  31.       }
  32.       this.obj = obj;
  33.       this.prop = prop;
  34.       this.begin = begin;
  35.       this.position = begin;
  36.       this.duration = duration;
  37.       this.useSeconds = useSeconds;
  38.       if(func)
  39.       {
  40.          this.func = func;
  41.       }
  42.       this.finish = finish;
  43.       this._listeners = [];
  44.       this.addListener(this);
  45.       this.start();
  46.    }
  47.    function set time(t)
  48.    {
  49.       this.prevTime = this._time;
  50.       if(t > this.duration)
  51.       {
  52.          if(this.looping)
  53.          {
  54.             this.rewind(t - this._duration);
  55.             this.update();
  56.             this.broadcastMessage("onMotionLooped",this);
  57.          }
  58.          else
  59.          {
  60.             if(this.useSeconds)
  61.             {
  62.                this._time = this._duration;
  63.                this.update();
  64.             }
  65.             this.stop();
  66.             this.broadcastMessage("onMotionFinished",this);
  67.          }
  68.       }
  69.       else if(t < 0)
  70.       {
  71.          this.rewind();
  72.          this.update();
  73.       }
  74.       else
  75.       {
  76.          this._time = t;
  77.          this.update();
  78.       }
  79.    }
  80.    function get time()
  81.    {
  82.       return this._time;
  83.    }
  84.    function set duration(d)
  85.    {
  86.       this._duration = !(d == null || d <= 0) ? d : _global.Infinity;
  87.    }
  88.    function get duration()
  89.    {
  90.       return this._duration;
  91.    }
  92.    function set FPS(fps)
  93.    {
  94.       var _loc2_ = this.isPlaying;
  95.       this.stopEnterFrame();
  96.       this._fps = fps;
  97.       if(_loc2_)
  98.       {
  99.          this.startEnterFrame();
  100.       }
  101.    }
  102.    function get FPS()
  103.    {
  104.       return this._fps;
  105.    }
  106.    function set position(p)
  107.    {
  108.       this.setPosition(p);
  109.    }
  110.    function setPosition(p)
  111.    {
  112.       this.prevPos = this._pos;
  113.       this.obj[this.prop] = this._pos = p;
  114.       this.broadcastMessage("onMotionChanged",this,this._pos);
  115.       updateAfterEvent();
  116.    }
  117.    function get position()
  118.    {
  119.       return this.getPosition();
  120.    }
  121.    function getPosition(t)
  122.    {
  123.       if(t == undefined)
  124.       {
  125.          t = this._time;
  126.       }
  127.       return this.func(t,this.begin,this.change,this._duration);
  128.    }
  129.    function set finish(f)
  130.    {
  131.       this.change = f - this.begin;
  132.    }
  133.    function get finish()
  134.    {
  135.       return this.begin + this.change;
  136.    }
  137.    function continueTo(finish, duration)
  138.    {
  139.       this.begin = this.position;
  140.       this.finish = finish;
  141.       if(duration != undefined)
  142.       {
  143.          this.duration = duration;
  144.       }
  145.       this.start();
  146.    }
  147.    function yoyo()
  148.    {
  149.       this.continueTo(this.begin,this.time);
  150.    }
  151.    function startEnterFrame()
  152.    {
  153.       if(this._fps == undefined)
  154.       {
  155.          _global.MovieClip.addListener(this);
  156.       }
  157.       else
  158.       {
  159.          this._intervalID = setInterval(this,"onEnterFrame",1000 / this._fps);
  160.       }
  161.       this.isPlaying = true;
  162.    }
  163.    function stopEnterFrame()
  164.    {
  165.       if(this._fps == undefined)
  166.       {
  167.          _global.MovieClip.removeListener(this);
  168.       }
  169.       else
  170.       {
  171.          clearInterval(this._intervalID);
  172.       }
  173.       this.isPlaying = false;
  174.    }
  175.    function start()
  176.    {
  177.       this.rewind();
  178.       this.startEnterFrame();
  179.       this.broadcastMessage("onMotionStarted",this);
  180.    }
  181.    function stop()
  182.    {
  183.       this.stopEnterFrame();
  184.       this.broadcastMessage("onMotionStopped",this);
  185.    }
  186.    function resume()
  187.    {
  188.       this.fixTime();
  189.       this.startEnterFrame();
  190.       this.broadcastMessage("onMotionResumed",this);
  191.    }
  192.    function rewind(t)
  193.    {
  194.       this._time = t != undefined ? t : 0;
  195.       this.fixTime();
  196.       this.update();
  197.    }
  198.    function fforward()
  199.    {
  200.       this.time = this._duration;
  201.       this.fixTime();
  202.    }
  203.    function nextFrame()
  204.    {
  205.       if(this.useSeconds)
  206.       {
  207.          this.time = (getTimer() - this._startTime) / 1000;
  208.       }
  209.       else
  210.       {
  211.          this.time = this._time + 1;
  212.       }
  213.    }
  214.    function onEnterFrame()
  215.    {
  216.       this.nextFrame();
  217.    }
  218.    function prevFrame()
  219.    {
  220.       if(!this.useSeconds)
  221.       {
  222.          this.time = this._time - 1;
  223.       }
  224.    }
  225.    function toString()
  226.    {
  227.       return "[Tween]";
  228.    }
  229.    function fixTime()
  230.    {
  231.       if(this.useSeconds)
  232.       {
  233.          this._startTime = getTimer() - this._time * 1000;
  234.       }
  235.    }
  236.    function update()
  237.    {
  238.       this.position = this.getPosition(this._time);
  239.    }
  240.    function func(t, b, c, d)
  241.    {
  242.       return c * t / d + b;
  243.    }
  244. }
  245.